<template>
  <div class="login-container">
    <div id="userRegisterPage">
      <h2 class="title">钰玟云图库 - 用户注册</h2>
      <div class="desc">
        企业级智能协同云图库
      </div>
      <a-form
        :model="formState"
        name="basic"
        autocomplete="off"
        label-align="left"
        @finish="handleSubmit"
        class="glass-form"
      >
        <a-form-item name="userAccount" :rules="[{required:true,message:'请输入账号'}]">
          <a-input v-model:value="formState.userAccount" placeholder="请输入账号" />
        </a-form-item>
        <a-form-item name="userPassword" :rules="[{
          required:true,
          message:'请输入密码'
        },{
          min:8,
          message:'密码不能小于8位'
        }]">
          <a-input-password v-model:value="formState.userPassword" placeholder="请输入密码" />
        </a-form-item>
        <a-form-item name="checkPassword" :rules="[{
          required:true,
          message:'请输入确认密码'
        },{
          min:8,
          message:'密码不能小于8位'
        }]">
          <a-input-password v-model:value="formState.checkPassword" placeholder="请输入确认密码" />
        </a-form-item>
        <div class="tips">
          已有账号？
          <RouterLink to="/user/login">去登录</RouterLink>
        </div>
        <a-form-item>
          <a-button type="primary" html-type="submit" style="width: 100%">
            注册
          </a-button>
        </a-form-item>
      </a-form>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { reactive } from 'vue'
import { message } from 'ant-design-vue'
import { userRegisterUsingPost } from '@/api/userController'
import { useRouter } from 'vue-router'

const router = useRouter()

const formState = reactive<API.UserRegisterDTO>({
  userAccount: '',
  userPassword: '',
  checkPassword: '',
})

const handleSubmit = async (values:any)=>{
  if(formState.userPassword !== formState.checkPassword){
    message.error('两次输入的密码不一致')
    return
  }
  const res = await userRegisterUsingPost(values)
  if(res.data.code === 0 && res.data.data) {
    message.success('注册成功')
    router.push({
      path:"/user/login",
      replace:true,
    })
  }else{
    message.error('注册失败，'+res.data.msg)
  }
}
</script>

<style scoped>
.login-container {
  /* 背景图片设置 */
  background-image: url('@/assets/loginbg.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  min-height: 88vh;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

#userRegisterPage {
  max-width: 360px;
  width: 100%;
}

.glass-form {
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 10px;
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
  width: 100%;
}

.title {
  text-align: center;
  margin-bottom: 16px;
  color: white;
  text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.desc {
  text-align: center;
  color: rgba(255,255,255,0.8);
  font-size: 16px;
  margin-bottom: 16px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.tips {
  margin-bottom: 16px;
  color: rgba(255,255,255,0.8);
  font-size: 13px;
  text-align: right;
}

/* 修改输入框样式 */
:deep(.ant-input),
:deep(.ant-input-password) {
  background-color: rgba(255, 255, 255, 0.2);
  color: white;
  border-color: rgba(255, 255, 255, 0.3);
}

:deep(.ant-input::placeholder) {
  color: rgba(255, 255, 255, 0.6);
}

/* 修改按钮样式 */
:deep(.ant-btn-primary) {
  background-color: rgba(24, 144, 255, 0.8);
  border-color: transparent;
}

:deep(.ant-btn-primary:hover) {
  background-color: rgba(24, 144, 255, 1);
}
</style>
